/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package proteoman.data;

import java.util.Map;
import java.util.HashMap;

/**
 *
 * @author gjj
 */
public class PeptideDataImpl implements PeptideData {

    protected String sequence;
    Map<ProteinData,Integer> mapProteinLocation;

    public PeptideDataImpl() {
        mapProteinLocation = new HashMap<ProteinData,Integer>();
    }

    public PeptideDataImpl(final String sequence) {
        if (sequence==null) {
            throw new java.lang.NullPointerException();
        }
        this.sequence = sequence;
        mapProteinLocation = new HashMap<ProteinData,Integer>();
    }

    public String getSequence() {
        return sequence;
    }

    public Map<ProteinData,Integer> getMapProteinLocation() {
        return mapProteinLocation;
    }

    public int getLocationInProtein(final ProteinData accession) {
        if (accession==null) {
            throw new java.lang.NullPointerException();
        }

        Integer loc = mapProteinLocation.get(accession);

        return loc==null ? -1 : loc;
    }

    public void setSequence(final String sequence) {
        if (sequence==null) {
            throw new java.lang.NullPointerException();
        }

        this.sequence = sequence;
    }

    public boolean setLocationInProtein(final ProteinData protein) {
        if (protein==null) {
            throw new java.lang.NullPointerException();
        }

        final String proseq = protein.getSequence();

        int loc = proseq.toUpperCase().indexOf(sequence.toUpperCase());
        if (loc>=0) {
            mapProteinLocation.put(protein, loc);
            return true;
        } else {
            return false;
        }
    }

}
